extends Node2D

var speed = 100
var ground_array = [preload("res://textures/Rocks/groundDirt.png"), 
preload("res://textures/Rocks/groundGrass.png"), 
preload("res://textures/Rocks/groundIce.png"), 
preload("res://textures/Rocks/groundSnow.png")]
var width:int = 0
var is_scrolling = false
# Called when the node enters the scene tree for the first time.
func _ready():
	change_ground($Sprite2D)
	change_ground($Sprite2D2)
	width = $Sprite2D.get_texture().get_width()
	pass

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	if Global.bg_start_scroll:
		for child in get_children():
			if child.position.x <= -width+1:
				change_ground(child)
				child.position.x = width-1
			child.position.x -= speed * delta

func change_ground(sprite:Sprite2D):
	var index = randi_range(0,ground_array.size()-1)
	Global.next_ground_type = index
	sprite.set_texture(ground_array[index])
